Description:
This message is reported when significant bits may be lost because of a conversion from a large integer type to a smaller integer type. Such conversions are always explicitly specified by the programmer, and MDL tries to reduce the number of reported messages caused by data truncation.
Incorrect:
The example below illustrates suspicious cases detected by MDL.
void ex1(int x, long y) {
byte b = (byte) (x >> 23);
short s = (short) (x & 0xffff00);
char c = (char) ((x & 0xffff) << 1);
int i = (int) (y >> 1);
}
Correct:
For the following example, no warning messages are produced.
void ex2(int x, long y) {
short s = (short) x;
char c = (char) x;
byte b = (byte) y;
b = (byte) (x & 0x7f);
b = (byte) c;
c = (char) (x & 0xffff);
x = (int) (y >> 33);
}